package com.cloud.custom.workflow.handler.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.alibaba.fastjson.JSON;
import com.cloud.custom.workflow.command.WfRequest;
import com.cloud.custom.workflow.command.WfResponse;
import com.cloud.custom.workflow.handler.SurroundHandler;

/**
 * 任务处置超时日志记录
 * 
 * @author taominglong
 *
 */
public class OverTimeLogHandler extends SurroundHandler {
	
	private static final Logger logger = LoggerFactory.getLogger(OverTimeLogHandler.class);

	private long timemillions = 0;

	@Override
	public void afterHandler(WfRequest request, WfResponse resp, ApplicationContext context) {
		long executedSec = (System.currentTimeMillis() - timemillions) / 1000;
		if (executedSec > 3) {
			if (logger.isDebugEnabled()) {
				logger.debug("指令执行超时日志: {}" + JSON.toJSONString(request));
			}
		}
	}

	@Override
	public void beforeHandler(WfRequest request, WfResponse resp, ApplicationContext context) {
		timemillions = System.currentTimeMillis();
	}

}
